/*
   LineDisplay.cpp
   
   Copyright (C) 2006 LinuxOne, Inc. <Republic of korea>

   This library is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation; either version 2.1
   of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   Lessor General Public License for more details.

   You should have received a copy of the GNU Lessor General Public
   License along with this library; if not, write to the Free Software
   Foundation, inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

   Hyunjin Kim <mgc521@linuxone.co.kr>

   LinuxOne, Inc., hereby disclaims all copylight
   written by Hyunjin Kim, 20 December 2006
*/

#include <services/LineDisplayService.h>

namespace booyopos
{

namespace services
{

CLineDisplayService::CLineDisplayService()
{
	deviceServiceDescription = "BooyoPOS LineDisplay Device Service";
	deviceServiceVersion = 0;
	physicalDeviceDescription = "Customer Line Display Device";
	physicalDeviceName = "CP20C2L";

	capBlink=DISP_CB_NOBLINK;
	capCharacterSet=false;
	capBitmap=false;
	capBlinkRate=false;
	capBrightness=false;
	capCustomGlyph=false;
	capCursorType=false;
	capDescriptors=false;
	capHMarquee=false;
	capICharWait=false;
	capMapCharacterSet=false;
	capPowerReporting=PR_NONE;
	capReadBack=DISP_CRB_NONE;
	capReverse=DISP_CR_NONE;
	capScreenMode=false;
	capStatisticsReporting=false;
	capUpdateStatistics=false;
	capCompareFirmwareVersion=false;
	capUpdateFirmware=false;
	capVMarquee=false;

	blinkRate=0;
	characterSet=DISP_CCS_ALPHA;
	characterSetList="";
	deviceColumns=20;
	columns=deviceColumns;
	currentWindow=0;
	cursorColumn=0;
	cursorType=DISP_CT_NONE;
	cursorRow=0;
	cursorUpdate=false;
	customGlyphList="";
	deviceBrightness=100;
	deviceDescriptors=0;
	deviceRows=2;
	deviceWindows=1;
	glyphHeight=24;
	glyphWidth=12;
	interCharacterWait=0;
	mapCharacterSet=false;
	marqueeRepeatWait=0;
	marqueeUnitWait=0;
	marqueeFormat=DISP_MF_WALK;
	marqueeType=DISP_MT_NONE;
	maximumX=240;
	maximumY=48;
	powerNotify=PN_DISABLED;
	powerState=PS_UNKNOWN;
	rows=deviceRows;
	screenMode=0;
	screenModeList="";
}

CLineDisplayService::~CLineDisplayService()
{
}

/* Capabilities */
int 
CLineDisplayService::GetCapBlink() 
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capBlink;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}


bool 
CLineDisplayService::GetCapBrightness() 
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capBrightness;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int 
CLineDisplayService::GetCapCharacterSet()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capCharacterSet;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapDescriptors()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capDescriptors;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapHMarquee()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capHMarquee;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapICharWait()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capICharWait;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapVMarquee()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capVMarquee;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetCapPowerReporting()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capPowerReporting;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapBlinkRate()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capBlinkRate;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetCapCursorType()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capCursorType;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapCustomGlyph()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capCustomGlyph;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetCapReadBack()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capReadBack;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetCapReverse()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capReverse;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapBitmap()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capBitmap;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapMapCharacterSet()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capMapCharacterSet;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapScreenMode()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capScreenMode;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapStatisticsReporting()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capStatisticsReporting;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapUpdateStatistics()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capUpdateStatistics;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapCompareFirmwareVersion()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capCompareFirmwareVersion;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCapUpdateFirmware()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return capUpdateFirmware;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

/* Properties */
int
CLineDisplayService::GetCharacterSet()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return characterSet;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetCharacterSet(int characterSet)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::characterSet = characterSet;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CLineDisplayService::GetCharacterSetList()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return characterSetList;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetColums()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return columns;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetCurrentWindow()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return currentWindow;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetCurrentWindow(int currentWindow)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::currentWindow = currentWindow;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetCursorColumn()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return cursorColumn;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetCursorColumn(int cursorColumn)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::cursorColumn = cursorColumn;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetCursorRow()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return cursorRow;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetCursorRow(int cursorRow)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::cursorRow = cursorRow;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetCursorUpdate()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return cursorUpdate;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetCursorUpdate(bool cursorUpdate)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::cursorUpdate = cursorUpdate;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetDeviceBrightness()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return deviceBrightness;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetDeviceBrightness(int deviceBrightness)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::deviceBrightness = deviceBrightness;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetDeviceColumns()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return deviceColumns;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetDeviceDescriptors()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return deviceDescriptors;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetDeviceRows()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return deviceRows;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetDeviceWindows()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return deviceWindows;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetInterCharacterWait()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return interCharacterWait;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetInterCharacterWait(int interCharacterWait)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::interCharacterWait = interCharacterWait;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetMarqueeFormat()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return marqueeFormat;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetMarqueeFormat(int marqueeFormat)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::marqueeFormat = marqueeFormat;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetMarqueeRepeatWait()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return marqueeRepeatWait;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetMarqueeRepeatWait(int marqueeRepeatWait)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::marqueeRepeatWait = marqueeRepeatWait;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetMarqueeType()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return marqueeType;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetMarqueeType(int marqueeType)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::marqueeType = marqueeType;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetMarqueeUnitWait()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return marqueeUnitWait;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetMarqueeUnitWait(int marqueeUnitWait)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::marqueeUnitWait = marqueeUnitWait;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetRows()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return rows;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetPowerNotify()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return powerNotify;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetPowerNotify(int powerNotify)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::powerNotify = powerNotify;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetPowerState()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return powerState;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetBlinkRate()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return blinkRate;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetBlinkRate(int blinkRate)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::blinkRate = blinkRate;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetCursorType()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return cursorType;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetCursorType(int cursorType)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::cursorType = cursorType;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CLineDisplayService::GetCustomGlyphList()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return customGlyphList;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetGlyphHeight()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return glyphHeight;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetGlyphWidth()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return glyphWidth;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CLineDisplayService::GetMapCharacterSet()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return mapCharacterSet;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetMapCharacterSet(bool mapCharacterSet)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::mapCharacterSet = mapCharacterSet;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetMaximumX()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return maximumX;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetMaximumY()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return maximumY;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CLineDisplayService::GetScreenMode()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return screenMode;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetScreenMode(int screenMode)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		CLineDisplayService::screenMode = screenMode;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CLineDisplayService::GetScreenModeList()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		return screenModeList;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

/* Added Methods */
void
CLineDisplayService::Initialize()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}

		char buf[2]={};

		buf[0]=0x1B;
		buf[1]=0x40;

		write(fd, buf, 2);

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

/* Methods */
void
CLineDisplayService::ClearDescriptors()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}

		char buf[5] = {};
		/* TO DO */

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::ClearText()
throw (CByException)
{
	char buf[5]={};
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		//CLR
		buf[0] = 0x0C;

		write(fd, buf, 1);

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::CreateWindow(int viewPortRow, int viewPortColumn, int viewPortHeight, int viewPortWidth, int windowHeight, int widowWidth)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		char buf[5]={};

		/* TO DO */
		// Make viewPort with parameter properties

		// Set maked windows properties

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::DestroyWindow()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	

		char buf[5]={};

		//ESC W s x1x2 y
		buf[0] = 0x1B;
		buf[1] = 0x57;
		buf[2] = 0x00;

		write(fd, buf, 5);

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::DisplayText(std::string data, int attribute)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		char buf[5]={};
		/* TO DO */

		if( attribute == DISP_DT_NORMAL )
		{

		}
		else if( attribute == DISP_DT_BLINK ) 
		{

		}
		else if( attribute == DISP_DT_REVERSE ) 
		{

		}
		else if( attribute == DISP_DT_BLINK_REVERSE ) 
		{

		}
		else
		{
			printf("Error \"DisplayText\" method !\n");
		}

		write(fd, data.c_str(), data.size());
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::DisplayTextAt(int row, int column, std::string data, int attribute)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}

		char buf[5]={};

		if( row <= deviceRows  || column <= deviceColumns)
		{
			//** MoveCursorToSpecifiedPosition **//
			//ESC 1 x y
			buf[0] = 0x1B;		//buf[0] = 0x1B;
			buf[1] = 0x6C;		//buf[0] = 0x6C;
			
			buf[2] = column;	//x
			buf[3] = row;		//y

			write(fd, buf, 5);
		}
		else
		{
			throw CByException(E_FAILURE, "Value Exceed Device's limit");

		}

		/* TO DO */

		if( attribute == DISP_DT_NORMAL )
		{

		}
		else if( attribute == DISP_DT_BLINK ) 
		{

		}
		else if( attribute == DISP_DT_REVERSE ) 
		{

		}
		else if( attribute == DISP_DT_BLINK_REVERSE ) 
		{

		}
		else
		{
			printf("Invalid attribute at \"DisplayTextAt\" method !\n");
		}

		write(fd, data.c_str(), data.size());

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::RefreshWindow(int window)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		char buf[5]={};
		/* TO DO */
		// Changes the current window to selected window

		SetCurrentWindow(window);


		// Redisplay selected window's viewport


	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::ScrollText(int direction, int units)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		char buf[5]={};
		/* TO DO */
		// Scroll Up & Down , Vertical
		//if( direction == DISP_ST_UP || direction == DISP_ST_DOWN )
			//VerticalScrollMode(device);

		// Scroll Left & Right , Horizen
		//if( direction == DISP_ST_LEFT || direction == DISP_ST_RIGHT )
			//HorizontalScrollMode(device);


	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetDescriptor(int descriptor, int attribute)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		char buf[5]={};
		/* TO DO */

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::DefineGlyph(int glyphcode, char* glyph)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		char buf[5]={};
		/* TO DO */

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::ReadCharacterAtCursor(int cursorData)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		char buf[5]={};
		/* TO DO */

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::DisplayBitmap(std::string fileName, int width, int alignmentX, int alignmentY)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		char buf[5]={};
		/* TO DO */

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::SetBitmap(int bitmapNumber, std::string fileName, int width, int alignmentX, int alignmentY)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		char buf[5]={};
		/* TO DO */

	}
	catch(CByException bye)
	{
		throw bye;
	}
}

/* Statistics */
void
CLineDisplayService::ResetStatistics(std::string statisticsBuffer)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::RestieveStatistics(std::string statisticsBuffer[])
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::UpdateStatistics(std::string statisticsBuffer)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::CompareFirmwareVersion(std::string firmwareFileName, int* result)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CLineDisplayService::UpdateFirmware(std::string firmwareFileName)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Device is not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

} // namespace services

} // namespace booyopos
